//
//  LaunchScreenView.swift
//  CMB250716
//
//  Created by Assistant on 2025-01-02.
//

import SwiftUI

struct LaunchScreenView: View {
    @State private var isLoading = true
    @State private var logoScale: CGFloat = LaunchConfig.Animation.logoInitialScale
    @State private var logoOpacity: Double = LaunchConfig.Animation.logoInitialOpacity
    
    var body: some View {
        ZStack {
            // 金黑色渐变背景
            LinearGradient(
                colors: [
                    Color(red: 0.8, green: 0.6, blue: 0.2), // 金色
                    Color(red: 0.05, green: 0.05, blue: 0.05) // 黑色
                ],
                startPoint: .top,
                endPoint: .bottom
            )
            .ignoresSafeArea()
            
            VStack(spacing: 30) {
                // Cu Mr Bull Logo
                Image("Logo") // 使用Logo.imageset中的Cu Mr Bull Logo
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 150, height: 150)
                    .scaleEffect(logoScale)
                    .opacity(logoOpacity)
                    .animation(.easeInOut(duration: LaunchConfig.logoAnimationDuration), value: logoScale)
                    .animation(.easeInOut(duration: LaunchConfig.logoAnimationDuration), value: logoOpacity)
                
                // 加载指示器
                if isLoading {
                    ProgressView()
                        .progressViewStyle(CircularProgressViewStyle(tint: .orange))
                        .scaleEffect(1.2)
                        .opacity(logoOpacity)
                        .animation(.easeInOut(duration: LaunchConfig.logoAnimationDuration).delay(0.2), value: logoOpacity)
                }
            }
        }
        .onAppear {
            // 快速启动动画
            withAnimation(.easeOut(duration: LaunchConfig.logoAnimationDuration)) {
                logoScale = LaunchConfig.Animation.logoFinalScale
                logoOpacity = LaunchConfig.Animation.logoFinalOpacity
            }
            
            // 优化启动速度：最小化启动画面显示时间
            let splashDuration = LaunchConfig.enableFastLaunch ? LaunchConfig.minimumSplashDuration : 0.8
            DispatchQueue.main.asyncAfter(deadline: .now() + splashDuration) {
                isLoading = false
            }
        }
    }
}

#Preview {
    LaunchScreenView()
}